 package com.oanda.blackberry.ui;
 
 import com.oanda.blackberry.restapi.Price;
 import com.oanda.blackberry.restapi.Quote;
 import com.oanda.blackberry.restapi.Rate;
 import com.oanda.blackberry.restapi.Symbol;
 import com.oanda.blackberry.util.DefaultController;
 import com.oanda.blackberry.util.Model;
 import com.oanda.blackberry.util.Settings;
 import net.rim.device.api.ui.Color;
 import net.rim.device.api.ui.Field;
 import net.rim.device.api.ui.Font;
 import net.rim.device.api.ui.Graphics;
 import net.rim.device.api.ui.component.CheckboxField;
 
 public class QuoteEditField extends CheckboxField
 {
   Color fontColor;
   Font normal = Font.getDefault().derive(0, 18);
   Font bigger = Font.getDefault().derive(0, 24);
   Font small = Font.getDefault().derive(0, 14);
 
   int horizontalPadding = 2;
   int verticalPadding = 2;
   protected static final int PADDING = 2;
   int width = 380;
   int height = 30;
   Quote quote;
   int state = 0;
 
   boolean isFocused = false;
 
   public QuoteEditField(long style, Quote quote, int state) {
     this.quote = quote;
     this.state = state;
   }
 
   public void setQuote(Quote quote) {
     this.quote = quote;
   }
 
   public void setState(int state) {
     this.state = state;
   }
 
   protected void layout(int maxWidth, int maxHeight) {
     setExtent(this.width, this.height);
   }
 
   protected void paint(Graphics graphics)
   {
     if (this.quote != null)
       drawPrice(graphics, 0, 0, this.width, this.height, this.quote.getSymbol(), this.quote.getBid(), this.quote.getAsk(), true, this.state);
   }
 
   public boolean isFocusable()
   {
     return false;
   }
 
   protected void drawFocus(Graphics graphics, boolean on)
   {
   }
 
   protected void onFocus(int direction)
   {
     this.isFocused = true;
     super.onFocus(direction);
     invalidate();
   }
 
   protected void onUnfocus() {
     this.isFocused = false;
     super.onUnfocus();
     invalidate();
   }
 
   private void drawPrice(Graphics graphics, int x, int y, int w, int h, String symbolName, double priceValue, double priceValue2, boolean selected, int state)
   {
     int symbolFontHeight = 24;
 
     Font font = DefaultController.getComponentFont().derive(0, symbolFontHeight);
     graphics.setFont(font);
 
     Symbol symbol = Model.getModel().getSettings().getRate().getSymbol(symbolName);
     if (symbol == null) {
       graphics.drawText("Err: " + symbolName + " " + Double.toString(priceValue), this.horizontalPadding + 3, y + this.verticalPadding + 3 + symbolFontHeight / 2);
       return;
     }
 
     if (selected) {
       graphics.setColor(16119285);
     }
     else if (state == 1)
       graphics.setColor(16711680);
     else if (state == 2)
       graphics.setColor(32768);
     else {
       graphics.setColor(8421504);
     }
 
     x = 70;
     int minWidth = 120;
 
     Price price = new Price(symbol, priceValue);
     graphics.setFont(this.small);
     graphics.drawText(price.getPippetteString(), x, y + this.verticalPadding, 0x30 | 0x5, minWidth);
     graphics.setFont(this.bigger);
     graphics.drawText(price.getMainPriceString(), x - this.horizontalPadding - this.small.getAdvance(price.getPippetteString()), y + this.verticalPadding, 0x30 | 0x5, minWidth);
     graphics.setFont(this.normal);
     graphics.drawText(price.getBaseString(), x - this.horizontalPadding - this.bigger.getAdvance(price.getMainPriceString()) - this.small.getAdvance(price.getPippetteString()), y + this.verticalPadding + 2 + 3, 0x30 | 0x5, minWidth);
 
     price = new Price(symbol, priceValue2);
     graphics.setFont(this.normal);
     x = 230;
     graphics.setFont(this.small);
     graphics.drawText(price.getPippetteString(), x, y + this.verticalPadding, 0x30 | 0x5, minWidth);
     graphics.setFont(this.bigger);
     graphics.drawText(price.getMainPriceString(), x - this.horizontalPadding - this.small.getAdvance(price.getPippetteString()), y + this.verticalPadding, 0x30 | 0x5, minWidth);
 
     graphics.setFont(this.normal);
     graphics.drawText(price.getBaseString(), x - this.horizontalPadding - this.bigger.getAdvance(price.getMainPriceString()) - this.small.getAdvance(price.getPippetteString()), y + this.verticalPadding + 2 + 3, 0x30 | 0x5, minWidth);
   }
}

